package com.t235.gc.biz.controller;

import com.t235.gc.AjaxResult;
import com.t235.gc.biz.service.BizService;
import com.t235.gc.entity.SysManager;
import com.t235.gc.entity.Venues;
import com.t235.gc.managerVo.SysManagerVo;
import com.t235.gc.orderVo.PartnersInviteVo;
import com.t235.gc.orderVo.RecyclersVo;
import com.t235.gc.orderVo.UserCashAuditVo;
import com.t235.gc.shenhe.ManagerAndRecordVo;
import com.t235.gc.shenhe.PartnersAndRecordVo;
import com.t235.gc.userIntiverVo.PageBean;
import com.t235.gc.userIntiverVo.UserInviterVo;
import com.t235.gc.venuesVo.VenuesVo;
import com.t235.gc.yunweiVo.FaultAndReplenishmentVo;
import com.t235.gc.yunweiVo.GoodsAndReplenishmentVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/biz")
@Api
public class BizController {
    @Autowired
    private BizService bizService;

    //查询用户提现审核列表
    @GetMapping("/userCashCheckQuery")
    public AjaxResult userCashCheckQuery(UserCashAuditVo vo){
        return AjaxResult.success(bizService.userCashCheckQuery(vo));
    }

    //修改用户提现审核通过
    @PutMapping("/pass/{cashId}")
    public AjaxResult pass(@PathVariable Integer cashId){
        return AjaxResult.success(bizService.updateStatus(cashId)==1 ? "审核成功":"审核失败");
    }
    
    //修改用户提现审核驳回
    @PutMapping("/reject/{cashId}")
    public AjaxResult reject(@PathVariable Integer cashId,/*@RequestBody(required = false) */String nayReason){
        return AjaxResult.success(bizService.updateStatusAndNayReason(cashId,nayReason)==1 ? "已驳回":"驳回失败");
    }


    //查询邀请合伙人审核列表
    @GetMapping("/partnersInviteQuery")
    public AjaxResult partnersInviteQuery(PartnersInviteVo vo){
        return AjaxResult.success(bizService.partnersInviteQuery(vo));
    }

    //查询回收员列表
    @GetMapping("/recyclersQuery")
    public AjaxResult recyclersQuery(RecyclersVo vo){
        return AjaxResult.success(bizService.recyclersQuery(vo));
    }

    /*//新增回收员
    @PostMapping("/addRecyclers")
    public AjaxResult addRecyclers(RecyclersVo vo){
        String address = vo.getAddress();
        String [] address1 = address.split("/");
        if(address1.length==4){
            vo.setProvince(address1[0]);
            vo.setCity(address1[1]);
            vo.setArea(address1[2]);
            vo.setStreet(address1[3]);
        }
        return AjaxResul0t.success(bizService.addRecyclers(vo));
    }*/

    @PostMapping("/addRecyclers")
    public AjaxResult addRecyclers(RecyclersVo vo){
        return AjaxResult.success(bizService.addRecyclers(vo));
    }

    @GetMapping("/selectRecyclersByRecyclersId")
    public AjaxResult selectRecyclersByRecyclersId(String recyclersid){
        return AjaxResult.success(bizService.selectRecyclersByRecyclersId(recyclersid));
    }















    //银行卡提现审核分页查询
    @GetMapping("selectAll")
    public AjaxResult selectFen(ManagerAndRecordVo managerAndRecordVo){
        List<ManagerAndRecordVo> list = bizService.selectFen(managerAndRecordVo);
        return AjaxResult.success(list);
    }

    //合伙人提现审核分页查询
    @GetMapping("selectFen2")
    public AjaxResult selectFen2(PartnersAndRecordVo partnersAndRecordVo){
        List<PartnersAndRecordVo> list = bizService.selectFen2(partnersAndRecordVo);
        return AjaxResult.success(list);
    }

    //修改用户提现审核通过
    @PutMapping("pass1/{cashId}")
    public AjaxResult pass1(@PathVariable Integer cashId){
        return AjaxResult.success(bizService.updateStatus1(cashId)==1 ? "审核成功":"审核失败");
    }

    //修改用户提现审核驳回
    @PutMapping("reject1/{cashId}")
    public AjaxResult reject1(@PathVariable Integer cashId,String nayReason){
        return AjaxResult.success(bizService.updateStatusAndNayReason1(cashId,nayReason)==1 ? "已驳回":"驳回失败");
    }

    //运维管理补货记录
    @GetMapping("selectbuhuo")
    public AjaxResult selectbuhuo(GoodsAndReplenishmentVo goodsAndReplenishmentVo){
        List<GoodsAndReplenishmentVo> list = bizService.selectBuHuo(goodsAndReplenishmentVo);
        return AjaxResult.success(list);
    }
    //运维故障处理记录
    @GetMapping("selectFault")
    public AjaxResult selectFault(FaultAndReplenishmentVo faultAndReplenishmentVo){
        List<FaultAndReplenishmentVo> list = bizService.selectFault(faultAndReplenishmentVo);
        return AjaxResult.success(list);
    }

    //场地管理列表
    @GetMapping("selectVenues")
    public AjaxResult selectVenues(VenuesVo venuesVo){
        List<VenuesVo> list = bizService.selectVenues(venuesVo);
        return AjaxResult.success(list);
    }
    //场地管理新增场地
    @GetMapping("AddVenues")
    public AjaxResult AddVenues(Venues venues){
        int count = bizService.AddVenues(venues);
        if (count>0){
            return AjaxResult.success(count);
        }else{
            return AjaxResult.error("失败");
        }
    }
    //场地管理删除
    @GetMapping("DelVenues")
    public AjaxResult DelVenues(Venues venues){
        int count = bizService.DelVenues(venues);
        if (count>0){
            return AjaxResult.success(count);
        }else{
            return AjaxResult.error("失败");
        }
    }
    //场地搜索venuesId来传值
    @GetMapping("selectVenuesId")
    public AjaxResult selectVenuesId(String venuesid){
        Venues venues =bizService.selectVenuedId(venuesid);
        return AjaxResult.success(venues);
    }

    //场地管理修改
    @GetMapping("UpdateVenues")
    public AjaxResult UpdateVenues(Venues venues){
        int count = bizService.UpdateVenues(venues);
        if (count>0){
            return AjaxResult.success(count);
        }else{
            return AjaxResult.error("失败");
        }
    }
    //搜索分练中心
    @GetMapping("/selectSort")
    public AjaxResult selectBySorting(SysManagerVo sysManagerVo,
                                      @RequestParam("page") int pageNum,
                                      @RequestParam("limit") int pageSize){
        PageBean pageBean=new PageBean();
        pageBean.setPageNum(pageNum);
        pageBean.setPageSize(pageSize);

        List<SysManagerVo> list= bizService.selectBySorting(sysManagerVo,pageBean.getPageNum(),pageBean.getPageSize());
        int totalSize= bizService.selectBySortingCount(sysManagerVo);
        /*
        * #账户剩余积分=全部的加-全部的减
           #充值总积分=全部的加
        * */
        List<SysManagerVo> balanceNumList= bizService.selectBySortingNum();// 查出减的积分
        for (int i = 0; i <list.size() ; i++) {
            int balanceAll = Integer.parseInt(list.get(i).getBalanceall()); //全部的加
            int balanceNum = Integer.parseInt(balanceNumList.get(i).getBalancenum());//全部的减
            int A=balanceAll-balanceNum;                            //账户剩余积分
            list.get(i).setBalancenum(String.valueOf(A));
        }

        //赋值给pageBean 返回出去
        pageBean.setDataList(list);
        pageBean.setTotalSize(totalSize);
        return AjaxResult.success(pageBean);
    }

    //通过id,查出数据   绑定
    @GetMapping("/selectByManagerId")
    public AjaxResult selectById(String managerId){
        SysManager sysManager= bizService.selectByManagerId(managerId);
        return AjaxResult.success(sysManager);
    }

    //添加分拣中心
    @GetMapping("/addBySorting")
    public AjaxResult addBySorting(SysManager sysManager){
        int count= bizService.addBySorting(sysManager);
        if (count>0){
            return AjaxResult.success(count);
        }else{
            return AjaxResult.error("失败");
        }
    }

    //修改分拣中心
    @PostMapping("/updateBySorting")
    public AjaxResult updateBySorting(SysManager sysManager){
        int count= bizService.updateBySorting(sysManager);
        return AjaxResult.success(count);
    }

    //删除分拣中心
    @GetMapping("/delBySorting")
    public AjaxResult delBySorting(String managerId){
        int count=bizService.delBySorting(managerId);
        if (count>0){
            return AjaxResult.success(count);
        }else{
            return AjaxResult.error("失败");
        }
    }

    //邀请用户
    @GetMapping("userInviter")
    public AjaxResult userInviter(UserInviterVo userInviterVo,
                                  @RequestParam("page") int pageNum,
                                  @RequestParam("limit") int pageSize){
        PageBean pageBean=new PageBean();
        pageBean.setPageNum(pageNum);
        pageBean.setPageSize(pageSize);

        //执行查询数据和查行数
        List<UserInviterVo> list=bizService.selectCount(userInviterVo,pageBean.getPageNum(),pageBean.getPageSize());
        int totalSize=bizService.selectUser(userInviterVo);

        //赋值给pageBean 返回出去
        pageBean.setDataList(list);
        pageBean.setTotalSize(totalSize);
        return AjaxResult.success(pageBean);

    }
}
